import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  //首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-s-data' }
    }]
  },
  // 用户管理
  {
    path: '/user',
    component: Layout,
    redirect: '/user/user',
    name: 'User',
    meta: { title: '用户管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/user/index.vue'),
        meta: { title: '会员管理', }
      },
      {
        path: 'address',
        name: 'Address',
        component: () => import('@/views/user/address/index.vue'),
        meta: { title: '收货地址', }
      },
      {
        path: 'collect',
        name: 'Collect',
        component: () => import('@/views/user/collect/collect.vue'),
        meta: { title: '会员收藏', }
      },
      {
        path: 'footprint',
        name: 'footprint',
        component: () => import('@/views/user/footprint/footprint.vue'),
        meta: { title: '会员足迹', }
      },
      {
        path: 'history',
        name: 'history',
        component: () => import('@/views/user/history/history.vue'),
        meta: { title: '搜索历史', }
      },
      {
        path: 'feedback',
        name: 'feedback',
        component: () => import('@/views/user/feedback/feedback.vue'),
        meta: { title: '意见反馈', }
      },

    ]
  },
  // 商场管理
  {
    path: '/mall',
    component: Layout,
    redirect: '/mall/region',
    name: 'Mall',
    meta: { title: '商场管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'region',
        name: 'region',
        component: () => import('@/views/mall/region/region.vue'),
        meta: { title: '行政区域', }
      },
      {
        path: 'brand',
        name: 'brand',
        component: () => import('@/views/mall/brand/brand.vue'),
        meta: { title: '品牌制造商', }
      },
      {
        path: 'category',
        name: 'category',
        component: () => import('@/views/mall/category/category.vue'),
        meta: { title: '商品类目', }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/mall/order/order.vue'),
        meta: { title: '订单管理', }
      },
      {
        path: 'aftersale',
        name: 'aftersale',
        component: () => import('@/views/mall/aftersale/aftersale.vue'),
        meta: { title: '售后管理', }
      },
      {
        path: 'issue',
        name: 'issue',
        component: () => import('@/views/mall/issue/issue.vue'),
        meta: { title: '通用问题', }
      },
      {
        path: 'keyword',
        name: 'keyword',
        component: () => import('@/views/mall/keyword/keyword.vue'),
        meta: { title: '关键词', }
      },

    ]
  },
  //商品管理
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/list',
    name: 'goods',
    meta: { title: '商品管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'list',
        name: 'list',
        component: () => import('@/views/goods/list/list.vue'),
        meta: { title: '商品列表', }
      },
      {
        path: 'edit',
        name: 'edit',
        component: () => import('@/views/goods/list/edit.vue'),
        // meta: { title: '商品编辑', }
      },
      {
        path: 'create',
        name: 'create',
        component: () => import('@/views/goods/create/create.vue'),
        meta: { title: '商品上架', }
      },
      {
        path: 'comment',
        name: 'crcommenteate',
        component: () => import('@/views/goods/comment/comment.vue'),
        meta: { title: '商品评论', }
      },

    ]
  },
  //推广管理
  {
    path: '/promotion',
    component: Layout,
    redirect: '/promotion/ad',
    name: 'promotion',
    meta: { title: '推广管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'ad',
        name: 'ad',
        component: () => import('@/views/promotion/ad/ad.vue'),
        meta: { title: '广告管理', }
      },
      {
        path: 'coupon',
        name: 'coupon',
        component: () => import('@/views/promotion/coupon/coupon.vue'),
        meta: { title: '优惠卷管理', }
      },
      {
        path: 'topic',
        name: 'topic',
        component: () => import('@/views/promotion/topic/topic.vue'),
        meta: { title: '专题管理', }
      },
      {
        path: 'groupon-rule',
        name: 'groupon-rule',
        component: () => import('@/views/promotion/groupon-rule/groupon-rule.vue'),
        meta: { title: '团购规则', }
      },
      {
        path: 'groupon-activity',
        name: 'groupon-activity',
        component: () => import('@/views/promotion/groupon-activity/groupon-activity.vue'),
        meta: { title: '团购活动', }
      },

    ]
  },
  //系统管理
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/admin',
    name: 'sys',
    meta: { title: '系统管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'admin',
        name: 'admin',
        component: () => import('@/views/sys/admin/admin.vue'),
        meta: { title: '管理员', }
      },
      {
        path: 'notice',
        name: 'notice',
        component: () => import('@/views/sys/notice/notice.vue'),
        meta: { title: '通知管理', }
      },
      {
        path: 'log',
        name: 'log',
        component: () => import('@/views/sys/log/log.vue'),
        meta: { title: '操作日志', }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/sys/role/role.vue'),
        meta: { title: '角色管理', }
      },
      {
        path: 'os',
        name: 'os',
        component: () => import('@/views/sys/os/os.vue'),
        meta: { title: '对象存储', }
      },



    ]
  },
  //配置管理
  {
    path: '/config',
    component: Layout,
    redirect: '/config/mall',
    name: 'config',
    meta: { title: '配置管理', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'mall',
        name: 'mall',
        component: () => import('@/views/config/mall/mall.vue'),
        meta: { title: '商场配置', }
      },
      {
        path: 'express',
        name: 'express',
        component: () => import('@/views/config/express/express.vue'),
        meta: { title: '运费配置', }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/config/order/order.vue'),
        meta: { title: '订单配置', }
      },
      {
        path: 'wx',
        name: 'wx',
        component: () => import('@/views/config/wx/wx.vue'),
        meta: { title: '小程序配置', }
      },




    ]
  },
  //统计报表
  {
    path: '/stat',
    component: Layout,
    redirect: '/stat/user',
    name: 'stat',
    meta: { title: '统计报表', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/stat/user/user.vue'),
        meta: { title: '用户统计', }
      },
      {
        path: 'order',
        name: 'order',
        component: () => import('@/views/stat/order/order.vue'),
        meta: { title: '订单统计', }
      },
      {
        path: 'goods',
        name: 'goods',
        component: () => import('@/views/stat/goods/goods.vue'),
        meta: { title: '商品统计', }
      },




    ]
  },


















  {
    path: '',
    component: Layout,
    meta: { title: '外链', icon: 'link' },
    children: [
      {
        path: 'https://cloud.tencent.com/product/cos',
        meta: { title: '腾讯云存储', icon: 'link' }
      },
      {
        path: 'https://cloud.tencent.com/product/sms',
        meta: { title: '腾讯云短信', icon: 'link' }
      },
      {
        path: 'https://pay.weixin.qq.com/index.php/core/home/login',
        meta: { title: '微信支付', icon: 'link' }
      },
      {
        path: 'https://mpkf.weixin.qq.com/',
        meta: { title: '小程序客服', icon: 'link' }
      },
      {
        path: 'https://www.alibabacloud.com/zh/product/object-storage-service?_p_lc=1',
        meta: { title: '阿里云存储', icon: 'link' }
      },
      {
        path: 'https://www.qiniu.com/products/kodo',
        meta: { title: '七牛云存储', icon: 'link' }
      },
      {
        path: 'https://www.kdniao.com/api-track',
        meta: { title: '快递鸟', icon: 'link' }
      }

    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
